import request from '@/utils/request';

/**
 * 分页查询销售单
 */
export async function pageSell(params) {
  const res = await request.get('/store/sell/page', { params });
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询销售单列表
 */
export async function listSell(params) {
  const res = await request.get('/store/sell', { params });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询销售单
 */
export async function getSell(id) {
  const res = await request.get('/store/sell/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加销售单
 */
export async function addSell(data) {
  const res = await request.post('/store/sell', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改销售单
 */
export async function updateSell(data) {
  const res = await request.put('/store/sell', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 修改收款,开票状态
 */
export async function updateTableState(data) {
  const res = await request.put('/store/sell/updateTableState', data);
  if (res.data.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除销售单
 */
export async function removeSell(id) {
  const res = await request.delete('/store/sell/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除销售单
 */
export async function removeSellAndSon(id) {
  const res = await request.delete('/store/sell/removeSellAndSon/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
